﻿#include "PrimaryEditor.h"
#include <qevent.h>

PrimaryEditor::PrimaryEditor()
	:
	QMainWindow{ nullptr ,Qt::FramelessWindowHint },
	current_btn{Qt::NoButton},
	current_mouse_point{}
{
	ui.setupUi(this);
	setAttribute(Qt::WA_TranslucentBackground);

	connect(ui.btn_close, &QToolButton::clicked, this, &PrimaryEditor::close);
	connect(ui.btn_min, &QToolButton::clicked, this, &PrimaryEditor::showMinimized);
	connect(ui.btn_restore, &QToolButton::clicked, this, &PrimaryEditor::showFull);

}

void PrimaryEditor::showFull()
{
	this->windowState() == Qt::WindowState::WindowNoState ? this->showFullScreen() : this->showNormal();
}

PrimaryEditor::~PrimaryEditor()
{
}

void PrimaryEditor::mousePressEvent(QMouseEvent* event)
{
	this->current_btn = event->button();
	this->current_mouse_point = event->globalPosition().toPoint() - this->pos();
}

void PrimaryEditor::mouseReleaseEvent(QMouseEvent* event)
{
	if (event->button() == this->current_btn)
	{
		this->current_btn = Qt::NoButton;
	}
}

void PrimaryEditor::mouseMoveEvent(QMouseEvent* event)
{
	if (current_btn == Qt::LeftButton)
	{
		this->move(event->globalPosition().toPoint() - this->current_mouse_point);
	}
}